home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <unistd.h>
- #include "exinterfmotif.h"
- #include <math.h>
- #include <string.h>
- #include "exbookglo.h"
- #include "exglobals.h"
-
- extern struct indexlist *(find_keyword_int() );
- extern struct indexlist *(add_keyword() );
- extern struct indexlist *find_keyword();
- extern struct icntmpltstruct *new_icn();
- extern struct grptmpltstruct *new_grp();
- extern struct pagestruct *new_pg();
- extern void readicon_i();
- extern struct filestruct *add_file();
- extern Boolean read_ascii();
- extern void ask_user_duplicate_icons(int dup_icn_cnt);
- extern void setChange();
-
- float *version_read;
- float version = .05;
- /* .02 had actual icon positions in the data file,
- .03 has indexices to an array of icon positions
- .04 pages stored as num icons on the front and then the icon stuff,
- num icons on the back and the icon stuff, groups also have a
- cover color
- .05 added integer representing a help file to the
- icon struct and the group struct */
- Boolean old_02, old_03, old_04;
- Boolean append = FALSE;
- static int numiconblocks = 1;
- static iconblocksize = 1024;
- static int iconlimit = 1023;
-
- struct indexlist **key_list;
- struct filestruct **file_list;
- struct icntmpltstruct **icon_list;
- int lastkey, lastfile, endicon;
-
- struct icntmpltstruct **duplicate_icons;
- int max_dup;
- int dup_icn_cnt;
-
- FILE *infp;
- FILE *outfp;
- char inbuf[70];
- char nullchar = '\0';
- char newline = '\n';
- char *thefile; /* buffer for the whole file when I'm reading it */
-
- int seticoncolor(int incolor)
- {
- short pc1, pc2;
- int outcolor;
- int i;
-
- if (incolor >= 0)
- {
- outcolor = incolor + 10;
- }
- else
- {
- incolor = -incolor;
- pc1 = incolor & 0xf;
- pc2 = (incolor & 0xf0) >> 4;
- if (pc1 == pc2)
- {
- outcolor = pc1 + 10;
- }
- else
- {
- if (pc2 > pc1) /* switch the order */
- {
- incolor = pc1;
- pc1 = pc2;
- pc2 = incolor;
- }
- outcolor = 25;
- for (i = 0; i < pc2; i++)
- outcolor = outcolor + (15-i);
- outcolor = outcolor + (pc1 - pc2);
- }
- }
- return(outcolor);
- }
-
- /************************************************************
- *
- * Read a WorkSpace icon file.
-
- currently, anything that is not a number is made black.
- iconcolor = -247, outlinecolor = 0
- *
- ************************************************************/
- int readicon_g(FILE *iconfp, struct icntmpltstruct *curicon, int cur_vertex)
- {
- struct polylist *headpoly;
- int bufndx;
- char tmp[20];
- int newpoly, nextpoly;
- int vert_count; /* count verts for this polygon*/
- int start_vertex;
- float xin, yin;
- int closed;
- int num_conv;
- int numpoly;
- int polycolor, linecolor;
- short r1, r2, g1, g2, b1, b2;
- int i,j;
- int len;
- float minx, maxx, miny, maxy;
- Boolean gotcolor;
- int first_vert;
- float xscale, yscale, scalefactor;
- float halfx, halfy;
- float xtrans, ytrans;
- float sizex, sizey;
- int idx;
-
- if (icon_verts == NULL)
- icon_verts = (MyPoint *)malloc(iconblocksize * sizeof(MyPoint));
- first_vert = cur_vertex;
- headpoly = curicon->poly;
- curicon->geofile->icon = curicon;
- minx = 100.0;
- miny = 100.0;
- maxx = -100.0;
- maxy = -100.0;
- nextpoly = 0;
- while ( fgets(inbuf,60,iconfp) != NULL)
- {
- /* find the first char that is not a tab */
- bufndx = 0;
- len = strlen(inbuf);
- while (bufndx < len+1 && inbuf[bufndx] == '\t')
- {
- bufndx++;
- }
- switch (inbuf[bufndx])
- {
- case '#':
- break;
- case 'b':
- vert_count = 0;
- start_vertex = cur_vertex;
- strncpy(tmp, &(inbuf[bufndx]), 17);
- if (strncmp(tmp, "bgnpolygon", 10) == 0)
- {
- newpoly = nextpoly;
- ++nextpoly;
- closed = 0;
- headpoly[newpoly].line = -1;
- headpoly[newpoly].type = 1;
- }
- else if (strncmp(tmp, "bgnoutlinepolygon", 17) == 0)
- {
- newpoly = nextpoly;
- ++nextpoly;
- closed = 1;
- vert_count++;
- headpoly[newpoly].type = 2;
- }
- else if (strncmp(tmp, "bgnline", 7) == 0)
- {
- newpoly = nextpoly;
- ++nextpoly;
- closed = 0;
- headpoly[newpoly].poly = -1;
- headpoly[newpoly].type = 3;
- }
- else if (strncmp(tmp, "bgnclosedline", 13) == 0)
- {
- newpoly = nextpoly;
- ++nextpoly;
- closed = 1;
- headpoly[newpoly].poly = -1;
- vert_count++;
- headpoly[newpoly].type = 4;
- }
- break;
- case 'e':
- strncpy(tmp, &(inbuf[bufndx]), 17);
- if (strncmp(tmp, "endpolygon", 10) == 0)
- {
- headpoly[newpoly].poly = polycolor;
- }
- else if (strncmp(tmp, "endline", 7) == 0)
- {
- headpoly[newpoly].line = polycolor;
- }
- else if (strncmp(tmp, "endclosedline", 13) == 0)
- {
- headpoly[newpoly].line = polycolor;
- }
- else if (strncmp(tmp, "endoutlinepolygon", 17) == 0)
- {
- headpoly[newpoly].poly = polycolor;
- gotcolor = FALSE;
- if ((num_conv = sscanf(&(inbuf[bufndx+18])," %d ",&linecolor))==1)
- gotcolor = TRUE;
- else if (num_conv!=1 && strncmp(&(inbuf[bufndx+18]), "iconcolor", 9)==0)
- {
- gotcolor = TRUE;
- linecolor = -247;
- }
- else if (num_conv!=1 && strncmp(&(inbuf[bufndx+18]), "outlinecolor", 12)==0)
- {
- gotcolor = TRUE;
- linecolor = 0;
- }
- if (gotcolor)
- {
- headpoly[newpoly].line = seticoncolor(linecolor);
- }
- }
-
- headpoly[newpoly].ndcs = (int *)malloc((vert_count+1)*sizeof(int) );
- for (i = start_vertex, j = 0; i < cur_vertex; i++, j++)
- {
- headpoly[newpoly].ndcs[j] = i;
- }
- if (closed == 1)
- headpoly[newpoly].ndcs[vert_count-1] = start_vertex;
- headpoly[newpoly].ndcs[vert_count] = -1;
-
- break;
- case 'c': /* color */
- gotcolor = FALSE;
- if ((num_conv = sscanf(&(inbuf[bufndx+6])," %d ",&polycolor))==1)
- gotcolor = TRUE;
- else if (num_conv!=1 && strncmp(&(inbuf[bufndx+6]), "iconcolor", 9)==0)
- {
- gotcolor = TRUE;
- polycolor = -247;
- }
- else if (num_conv!=1 && strncmp(&(inbuf[bufndx+6]), "outlinecolor", 12)==0)
- {
- gotcolor = TRUE;
- polycolor = 0;
- }
- if (gotcolor)
- {
- polycolor = seticoncolor(polycolor);
- /* iconcolor (-247) becomes 117 */
- }
- break;
- case 'v':
- {
- strncpy(tmp, &(inbuf[bufndx]), 6);
- if (strncmp(tmp, "vertex", 6) == 0)
- {
- /* The vertex data should be a string of the */
- /* form: vertex(xx.x, yy.y). Using atof, read */
- /* the substrings starting at idx 7, and at the */
- /* first character following the ",". This is */
- /* faster than using sscanf. */
- idx = 7;
- while( inbuf[idx] != ',' ) idx++;
- xin = (float)atof( &(inbuf[bufndx+7]) );
- yin = (float)atof( &(inbuf[idx+1]) );
-
- icon_verts[cur_vertex][0] = xin;
- icon_verts[cur_vertex][1] = yin;
- icon_verts[cur_vertex][2] = 0.0;
- if (icon_verts[cur_vertex][0] > maxx)
- maxx = icon_verts[cur_vertex][0];
- if (icon_verts[cur_vertex][0] < minx)
- minx = icon_verts[cur_vertex][0];
- if (icon_verts[cur_vertex][1] > maxy)
- maxy = icon_verts[cur_vertex][1];
- if (icon_verts[cur_vertex][1] < miny)
- miny = icon_verts[cur_vertex][1];
- ++cur_vertex;
- ++vert_count;
- if (cur_vertex > iconlimit)
- {
- numiconblocks++;
- icon_verts = (MyPoint *)realloc( (void *)icon_verts, numiconblocks *
- iconblocksize * sizeof(MyPoint));
- iconlimit = numiconblocks * iconblocksize - 1;
- }
- }
- }
- break;
- default:
- break;
- }
- } /* end of while fgets */
- sizex = maxx - minx;
- sizey = maxy - miny;
- /* do as michelle did, not as she said */
- /* scalefactor = (sizex > sizey) ? 1.8 / sizex : 1.8 / sizey; */
- scalefactor = (sizex > sizey) ? 1.6 / sizex : 1.6 / sizey;
- xtrans = 1.0 - ((maxx + minx) * scalefactor / 2.0);
- /* do as michelle did not as she said */
- /* ytrans = 1.2375 - ((maxy + miny) * scalefactor / 2.0); */
- ytrans = 1.1 - ((maxy + miny) * scalefactor / 2.0);
- for (i = first_vert; i < cur_vertex; i++)
- {
- icon_verts[i][0] = (icon_verts[i][0] * scalefactor) + xtrans;
- icon_verts[i][1] = (icon_verts[i][1] * scalefactor) + ytrans;
- /* z is always 0 */
- }
-
- return(cur_vertex);
- }
-
- /************************************************************
- *
- * Write the icons into the file. The icons are stored as:
- * a character representing the type of icon.
- * a short associated with the demo name in the index
- * a short as a pointer to the geo icon file name
- * a short as a pointer to the img icon file name
- * a short as a pointer to the help file name 2/18/93 .05
- * a list of shorts (ended by -1) as pointers to the other files
- * a short representing the number of keywords
- * a short for each keyword.
- * a string term. by nullchar for the alternate startstring 2/18/93 .05
- *
- ************************************************************/
- int write_icon(struct icntmpltstruct *iconptr)
- {
- struct wordlist *wrdptr;
- struct filelist *flptr;
- int i;
- int bytecount;
- short none;
- int length;
-
- none = -1;
- /* type (geom/image) of icon */
- bytecount = 0;
- fwrite(&(iconptr->filetype),sizeof(char),1,outfp);
- bytecount = bytecount + sizeof(char);
- /* write name */
- fwrite(&(iconptr->nameptr->num),sizeof(short),1,outfp);
- bytecount = bytecount + sizeof(short);
- /* write integers for pointers to files */
- if (iconptr->geofile != NULL)
- {
- fwrite(&(iconptr->geofile->count),sizeof(short),1, outfp);
- }
- else
- fwrite(&(none),sizeof(short),1, outfp);
- bytecount = bytecount + sizeof(short);
- if (iconptr->imgfile != NULL)
- fwrite(&(iconptr->imgfile->count),sizeof(short),1, outfp);
- else
- fwrite(&(none),sizeof(short),1, outfp);
- bytecount = bytecount + sizeof(short);
-
- if (iconptr->helpfile != NULL)
- fwrite(&(iconptr->helpfile->count),sizeof(short),1, outfp);
- else
- fwrite(&(none),sizeof(short),1, outfp);
- bytecount = bytecount + sizeof(short);
-
- flptr = iconptr->addtlfiles;
- while(flptr != NULL)
- {
- if (flptr->file != NULL)
- {
- fwrite(&(flptr->file->count),sizeof(short),1, outfp);
- bytecount = bytecount + sizeof(short);
- }
- flptr = flptr->next;
- }
- /* end the list of additional files with a negative one */
- fwrite(&(none),sizeof(short),1, outfp);
- bytecount = bytecount + sizeof(short);
- /* write keywords */
- fwrite(&(iconptr->numkey),sizeof(short),1,outfp);
- bytecount = bytecount + sizeof(short);
- wrdptr = iconptr->keywords;
- for (i = 0; i < iconptr->numkey; i++)
- {
- fwrite(&(wrdptr->indexptr->num),sizeof(short),1,outfp);
- bytecount = bytecount + sizeof(short);
- wrdptr = wrdptr->next;
- }
- /* write out the alternate start string */
- if (iconptr->alt_command != NULL)
- {
- length = strlen(curicon->alt_command);
- fwrite(curicon->alt_command,sizeof(char),length,outfp);
- bytecount = bytecount + length;
- }
- fwrite(&nullchar,sizeof(char),1,outfp);
- bytecount++;
-
- fwrite(&newline,sizeof(char),1,outfp);
- bytecount++;
- return(bytecount);
- }
-
- /************************************************************
- *
- * Reads the file buffer for each icon in the book. Icons
- * are stored as:
- * a character representing the type of icon.
- * a short associated with the demo name in the index
- * an integer as a pointer to the geo icon file name 8/21/91
- * an integer as a pointer to the img icon file name 8/21/91
- * a short as a pointer to the help file name 2/18/93 .05
- * a list of integers (ended by -1) as pointers to the other files 8/21/91
- * a short representing the number of keywords
- * a short for each keyword.
- * a string term. by nullchar for the alternate startstring 2/18/93 .05
- *
- ************************************************************/
- read_icons(int intofile, int endoficons)
- {
- char *charptr;
- char *end;
- char *bc;
- int iconcount;
- short numkeys;
- struct wordlist *wrdptr;
- int i;
- short j;
- struct icntmpltstruct *curicon;
- int filendx;
- short indx;
- struct filelist *lastfl, *flptr;
- struct filestruct *fptr;
- int kl_limit, kl_bc, kl_size, kl_count;
- struct indexlist *tmpndxptr;
- char tmpfiletype;
- int length;
- char tmpstor[10];
-
- dup_icn_cnt = 0;
- max_dup = 32;
- duplicate_icons = (struct icntmpltstruct **) malloc
- ( max_dup* sizeof(struct icntmpltstruct *));
- end = &( thefile[intofile+endoficons]);
- bc = &( thefile[intofile] );
- iconcount = 0;
- kl_size = 50;
- kl_limit = kl_size;
- kl_count = 0;
- kl_bc = 1;
- icon_list = (struct icntmpltstruct **)malloc(kl_limit * sizeof(struct icntmpltstruct *) );
- while (bc < end)
- {
- tmpfiletype = *bc;
- bc++;
- curicon = new_icn();
- icon_list[kl_count] = curicon;
- kl_count++;
- if (kl_count == kl_limit)
- {
- kl_bc++;
- kl_limit = kl_bc * kl_size;
- icon_list = (struct icntmpltstruct **)realloc( (void *)icon_list,
- kl_limit * sizeof(struct icntmpltstruct *) );
- }
- if (firsticon == NULL)
- firsticon = curicon;
- else
- lasticon->nexticntmplt = curicon;
- lasticon = curicon;
- curicon->ok = TRUE;
- curicon->filetype = tmpfiletype;
- /* read name */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- bc += sizeof(short);
- tmpndxptr = key_list[indx];
- curicon->nameptr = tmpndxptr;
- tmpndxptr->count++;
- if (tmpndxptr != NULL && tmpndxptr->icon != NULL)
- {
- duplicate_icons[dup_icn_cnt] = curicon;
- dup_icn_cnt++;
- if (dup_icn_cnt == max_dup)
- {
- max_dup = max_dup + 32;
- duplicate_icons = (struct icntmpltstruct **) realloc
- ( (void *) duplicate_icons, max_dup* sizeof(struct icntmpltstruct *));
- }
- }
- else
- {
- if (curicon->nameptr == NULL)
- curicon->nameptr = add_keyword("dontknow");
- else
- curicon->nameptr->icon = curicon;
- }
- /* read files */
- /* geo icon file */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- filendx = *((short*)tmpstor);
- if (filendx >= 0)
- {
- curicon->geofile = file_list[filendx];
- file_list[filendx]->occurences++;
- }
- bc += sizeof(short);
- /* img icon file */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- filendx = *((short*)tmpstor);
- if (filendx >= 0)
- {
- curicon->imgfile = file_list[filendx];
- file_list[filendx]->occurences++;
- }
- bc += sizeof(short);
- do_iconfiles(curicon);
- if (!(old_02 || old_03 || old_04) )
- {
- /* help file */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- filendx = *((short*)tmpstor);
- if (filendx >= 0)
- {
- curicon->helpfile = file_list[filendx];
- file_list[filendx]->occurences++;
- }
- else
- curicon->helpfile = NULL;
- bc += sizeof(short);
- }
- /* additional files */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- filendx = *((short*)tmpstor);
- lastfl = NULL;
- curicon->ok = TRUE;
- curicon->addtlfiles = NULL;
- while (filendx >= 0 ) /*&& filendx < lastfile) */
- {
- flptr = (struct filelist *)malloc(sizeof(struct filelist) );
- flptr->file = NULL;
- flptr->next = NULL;
- flptr->file = file_list[filendx];
- file_list[filendx]->occurences++;
- if (flptr->file == NULL || !(flptr->file->ok))
- {
- curicon->ok = FALSE;
- }
- if (lastfl == NULL)
- {
- curicon->addtlfiles = flptr;
- lastfl = flptr;
- }
- else
- {
- lastfl->next = flptr;
- lastfl = flptr;
- }
- lastfl->next = NULL;
- bc += sizeof(short);
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- filendx = *((short*)tmpstor);
- }
- bc += sizeof(short);
- /* read number of keywords */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- curicon->numkey = *((short *)tmpstor);
- bc += sizeof(short);
- /* read keywords */
- if (curicon->numkey > 0)
- {
- wrdptr=(struct wordlist *)malloc(sizeof(struct wordlist));
- wrdptr->next = NULL;
- wrdptr->indexptr = NULL;
- curicon->keywords = wrdptr;
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- bc += sizeof(short);
- if (indx >= 0 && indx < lastkey)
- {
- wrdptr->indexptr = key_list[indx];
- key_list[indx]->count++;
- }
- if (wrdptr->indexptr != NULL)
- index_add_demo(wrdptr->indexptr, curicon);
- for (j = 1; j < curicon->numkey; j++)
- {
- if (wrdptr->indexptr != NULL)
- {
- wrdptr->next=(struct wordlist *)malloc(sizeof(struct wordlist));
- wrdptr = wrdptr->next;
- wrdptr->next = NULL;
- wrdptr->indexptr = NULL;
- }
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- bc += sizeof(short);
- if (indx >= 0 && indx < lastkey)
- {
- wrdptr->indexptr = key_list[indx];
- key_list[indx]->count++;
- }
- if (wrdptr->indexptr != NULL)
- index_add_demo(wrdptr->indexptr, curicon);
- /* ERROR if the last keyword is not found */
- }
- }
- /* set xsize */
- curicon->xsize = 1.0;
- /* read alternate start string */
- if (!(old_02 || old_03 || old_04) )
- {
- length = strlen(bc);
- if (length > 0)
- {
- curicon->alt_command = (char *) malloc ( length + 1 );
- strncpy(curicon->alt_command, bc, length+1);
- }
- else
- curicon->alt_command = NULL;
- bc+=(length+1);
- }
- bc++; /* skip the newline */
- ++iconcount;
- }
- numberoficons = numberoficons + iconcount; /* global */
- for (i = kl_count; i < kl_limit; i++)
- icon_list[i] = NULL;
- endicon = kl_limit;
- }
-
- Boolean check_start_string(int icon_num)
- {
- int i;
- int cmp_rslt;
-
-
- }
-
- /************************************************************
- *
- * This routine reads the start strings. They are stored
- * in the file consecutively, and are associated with the
- * correct demo by position in the list.
- *
- ************************************************************/
- read_start_strings(int intofile, int endofss)
- {
- int count, length;
- char *bc, *end;
- struct icntmpltstruct *curicon;
-
- bc = &( thefile[intofile] );
- end = &( thefile[intofile +endofss]);
- count = 0;
- curicon = icon_list[count];
- while (bc < end)
- {
- length = strlen(bc);
- set_start_string( curicon, bc);
- count++;
- bc+=length; /* move over this start string */
- bc++; /* skip the null character */
- curicon = icon_list[count];
- }
- }
-
- /************************************************************
- *
- * Write out a page. Each page is stored as:
- * an integer -- the number of icons
- * for each icon, the icon number (an integer)
- * two floats -- the x and y position of the icon on the page
- *
- ************************************************************/
- write_page(struct pagestruct *pgptr)
- {
- int bytecount;
- int i;
- struct iconstruct *tmpiconptr;
- int side;
-
- /* write icon number and location */
- /* front of page */
- fwrite(&(pgptr->frontnumicons),sizeof(int),1,outfp);
- bytecount = sizeof(int);
- tmpiconptr = pgptr->fronticons;
- for (i = 0; i < pgptr->frontnumicons; i++)
- {
- tmpiconptr->iconnum = tmpiconptr->iconptr->iconnum;
- /* ERROR don't really need the iconnum field in the iconstruct*/
- fwrite(&(tmpiconptr->iconnum),sizeof(int),1,outfp);
- bytecount = bytecount + sizeof(int);
- fwrite(&(tmpiconptr->xposition_ndx),sizeof(short),1,outfp);
- bytecount = bytecount+ sizeof(short);
- fwrite(&(tmpiconptr->yposition_ndx),sizeof(short),1,outfp);
- bytecount = bytecount+ sizeof(short);
- tmpiconptr = tmpiconptr ->nexticon;
- }
-
- fwrite(&(pgptr->backnumicons),sizeof(int),1,outfp);
- bytecount = bytecount + sizeof(int);
- tmpiconptr = pgptr->backicons;
- for (i = 0; i < pgptr->backnumicons; i++)
- {
- tmpiconptr->iconnum = tmpiconptr->iconptr->iconnum;
- /* ERROR don't really need the iconnum field in the iconstruct*/
- fwrite(&(tmpiconptr->iconnum),sizeof(int),1,outfp);
- bytecount = bytecount + sizeof(int);
- fwrite(&(tmpiconptr->xposition_ndx),sizeof(short),1,outfp);
- bytecount = bytecount+ sizeof(short);
- fwrite(&(tmpiconptr->yposition_ndx),sizeof(short),1,outfp);
- bytecount = bytecount+ sizeof(short);
- tmpiconptr = tmpiconptr ->nexticon;
- }
-
- return(bytecount);
- }
-
- /************************************************************
- *
- * Read all of the pages for a group. Each page is stored as:
- * an integer -- the number of icons
- * for each icon, the icon number (an integer)
- * two floats -- the x and y position of the icon on the page
- *
- ************************************************************/
- char *read_pages(char *pbc, int numpg, struct grptmpltstruct *grpptr)
- {
- struct pagestruct *pgptr, *prevpgptr;
- int i, j, k;
- struct icntmpltstruct *curicon;
- struct grpliststruct *glistptr;
- struct iconstruct *tmpiconptr, *previconptr;
- short xiconpos, yiconpos;
- Boolean old_ok;
- char tmpstor[10];
-
- prevpgptr = grpptr->lastpage;
- old_ok = grpptr->ok;
- grpptr->ok = FALSE;
- for (i = 0; i < numpg; i++)
- {
- xiconpos = 0;
- yiconpos = 3;
- pgptr = new_pg();
- if (grpptr->firstpage == NULL)
- grpptr->firstpage = pgptr;
- else
- prevpgptr->nextpage = pgptr;
- grpptr->lastpage = pgptr;
- pgptr->prevpage = prevpgptr;
- prevpgptr = pgptr;
- pgptr->direction = 1;
- for (k = 0; k < sizeof(int); k++)
- tmpstor[k] = pbc[k];
- pgptr->frontnumicons = *( (int *)tmpstor);
- pbc+=sizeof(int);
- previconptr = NULL;
- for (j = 0; j < pgptr->frontnumicons; j++)
- {
- tmpiconptr = (struct iconstruct *)malloc(sizeof(struct iconstruct) );
- tmpiconptr->nexticon = NULL;
- if (pgptr->fronticons == NULL)
- pgptr->fronticons = tmpiconptr;
- else
- previconptr->nexticon = tmpiconptr;
- previconptr = tmpiconptr;
- for (k = 0; k < sizeof(int); k++)
- tmpstor[k] = pbc[k];
- tmpiconptr->iconnum = *( (int *) tmpstor);
- pbc+=sizeof(int);
- curicon = icon_list[tmpiconptr->iconnum];
- (curicon->occurences)+=1;
- tmpiconptr->iconptr = curicon;
- tmpiconptr->ok = curicon->ok;
- if (tmpiconptr->ok)
- {
- grpptr->ok = TRUE;
- }
- glistptr = (struct grpliststruct *)malloc(sizeof(struct grpliststruct) );
- glistptr->next = NULL;
- glistptr->prev = NULL;
- if (curicon->grps == NULL)
- curicon->grps = glistptr;
- else
- {
- glistptr->next = curicon->grps;
- curicon->grps = glistptr;
- }
- glistptr->grpptr = grpptr;
-
- if (old_02 == TRUE)
- {
- pbc+=sizeof(float); /* skip icon origin x */
- pbc+=sizeof(float); /* skip icon origin y & rot_or y */
- tmpiconptr->xposition_ndx = xiconpos;
- tmpiconptr->yposition_ndx = yiconpos;
- xiconpos++;
- if (xiconpos > 4)
- {
- xiconpos = 0;
- yiconpos--;
- }
- }
- else
- {
- for (k = 0; k < sizeof(short); k++)
- tmpstor[k] = pbc[k];
- tmpiconptr->xposition_ndx = *( (short *) tmpstor);
- pbc+=sizeof(short);
- for (k = 0; k < sizeof(short); k++)
- tmpstor[k] = pbc[k];
- tmpiconptr->yposition_ndx = *( (short *) tmpstor);
- pbc+=sizeof(short);
- }
- tmpiconptr = tmpiconptr->nexticon;
- }
- /* version .04 might have icons on the backs of the pages */
- if ( !old_02 && !old_03)
- {
- for (k = 0; k < sizeof(int); k++)
- tmpstor[k] = pbc[k];
- pgptr->backnumicons = *( (int *)tmpstor);
- pbc+=sizeof(int);
- if (pgptr->backnumicons <= 0)
- pgptr->backicons = NULL;
- else
- {
- pgptr->backicons = NULL;
- /*
- previconptr = NULL;
- */
- for (j = 0; j < pgptr->backnumicons; j++)
- {
- tmpiconptr = (struct iconstruct *)
- malloc(sizeof(struct iconstruct) );
- tmpiconptr->nexticon = NULL;
- if (pgptr->fronticons == NULL)
- pgptr->fronticons = tmpiconptr;
- else
- previconptr->nexticon = tmpiconptr;
- previconptr = tmpiconptr;
-
- for (k = 0; k < sizeof(int); k++)
- tmpstor[k] = pbc[k];
- tmpiconptr->iconnum = *( (int *) tmpstor);
- pbc+=sizeof(int);
- curicon = icon_list[tmpiconptr->iconnum];
- (curicon->occurences)+=1;
- tmpiconptr->iconptr = curicon;
- tmpiconptr->ok = curicon->ok;
- if (tmpiconptr->ok)
- {
- grpptr->ok = TRUE;
- }
- glistptr = (struct grpliststruct *)malloc(sizeof(struct grpliststruct) );
- glistptr->next = NULL;
- glistptr->prev = NULL;
- if (curicon->grps == NULL)
- curicon->grps = glistptr;
- else
- {
- glistptr->next = curicon->grps;
- curicon->grps = glistptr;
- }
- glistptr->grpptr = grpptr;
-
- for (k = 0; k < sizeof(short); k++)
- tmpstor[k] = pbc[k];
- tmpiconptr->xposition_ndx = *( (short *) tmpstor);
- pbc+=sizeof(short);
- for (k = 0; k < sizeof(short); k++)
- tmpstor[k] = pbc[k];
- tmpiconptr->yposition_ndx = *( (short *) tmpstor);
- pbc+=sizeof(short);
- tmpiconptr = tmpiconptr->nexticon;
- }
- }
- }
- else
- {
- pgptr->backicons = NULL;
- pgptr->backnumicons = 0;
- }
- }
- grpptr->lastpage = pgptr;
- grpptr->ok = grpptr->ok && old_ok;
- return(pbc);
- }
-
- /************************************************************
- *
- * Write out a group. Each group is stored as:
- * a short -- the number of pages
- * a short -- the number of the group name
- * a short -- the type of artwork on the page (unused)
- * 3 floats -- the cover color (0 - 1.0)
- * a short -- index for the help file 2/18/93 .05
- * a short -- the number of keywords
- * shorts -- for each keyword, its number in the index
- *
- ************************************************************/
- write_group(struct grptmpltstruct *grpptr)
- {
- struct wordlist *wrdptr;
- int i;
- int bytecount;
- short none;
-
- none = -1;
- fwrite(&(grpptr->numpages),sizeof(short),1,outfp);
- bytecount = sizeof(short);
- /* write name */
- fwrite(&(grpptr->nameptr->num),sizeof(short),1,outfp);
- bytecount = bytecount + sizeof(short);
-
- /* type for group artwork */
- fwrite(&(grpptr->arttype),sizeof(short),1,outfp);
- bytecount = bytecount + sizeof(short);
-
- /* write cover color */
- fwrite( &(grpptr->covercolor[0]), sizeof(float), 3, outfp);
- bytecount = bytecount + 3 * sizeof(float);
-
- /* write index for help file */
- if (grpptr->helpfile != NULL)
- fwrite(&(grpptr->helpfile->count),sizeof(short),1, outfp);
- else
- fwrite(&(none),sizeof(short),1, outfp);
- bytecount = bytecount + sizeof(short);
-
- /* write group keywords */
- fwrite(&(grpptr->numkey),sizeof(short),1,outfp);
- bytecount = bytecount + sizeof(short);
- wrdptr = grpptr->keywords;
- for (i = 0; i < grpptr->numkey; i++)
- {
- fwrite(&(wrdptr->indexptr->num),sizeof(short),1,outfp);
- bytecount = bytecount + sizeof(short);
- wrdptr = wrdptr->next;
- }
- return(bytecount);
- }
- /************************************************************
- *
- * Make each group's list of icons continuous across page
- * and page side boundaries.
- *
- ************************************************************/
- void fix_icon_pointers(struct grptmpltstruct *grpptr)
- {
- struct pagestruct *pgptr;
- struct iconstruct *tmpicn, *holdicon, *bicnptr, *ficnptr;
-
- if (grpptr->firstpage->backicons != NULL || grpptr->numpages > 1)
- {
- pgptr = grpptr->firstpage;
- holdicon = NULL;
- while (pgptr != NULL)
- {
- tmpicn = pgptr->fronticons;
- if (holdicon != NULL)
- holdicon->nexticon = tmpicn;
- /* if there are no backicons, this loop will stop when
- tmpicn == NULL. If there are, it will stop at
- the end of the front page. */
- while (tmpicn != pgptr->backicons)
- {
- holdicon = tmpicn;
- tmpicn = tmpicn->nexticon;
- }
- if (pgptr->backicons != NULL)
- {
- tmpicn = pgptr->backicons;
- if (holdicon != NULL)
- holdicon->nexticon = tmpicn;
- if (pgptr->nextpage != NULL)
- ficnptr = pgptr->nextpage->fronticons;
- else
- ficnptr = NULL;
- /* if there is not a next page, this loop will stop
- when tmpicn = NULL, If there is a next page, this
- loop will stop at the end of the backside of this page */
- while (tmpicn != ficnptr && tmpicn != NULL)
- {
- holdicon = tmpicn;
- tmpicn = tmpicn->nexticon;
- }
- }
- pgptr = pgptr->nextpage;
- }
- }
- }
-
- /************************************************************
- *
- * Read all the groups. Each group is stored as:
- * a short -- the number of pages
- * a short -- the number of the group name
- * a short -- the type of artwork on the page (unused)
- * 3 floats -- the cover color (0 - 1.0)
- * a short -- index for the help file 2/18/93 .05
- * a short -- the number of keywords
- * shorts -- for each keyword, its number in the index
- *
- ************************************************************/
- read_groups(char *bc, char *end, char *pbc)
- {
- struct grptmpltstruct *newgrpptr, *prevg;
- char *newword;
- struct wordlist *wrdptr, *prevptr, *lastptr;
- int count;
- int numnewgroups;
- int tmpnumpages;
- struct indexlist *tmpndxptr;
- struct grptmpltstruct *tmpgrp;
- short tmpnumkey;
- int indx;
- char tmpstor[10];
- int i;
-
- prevg = lastgroup;
- numnewgroups = 0;
- while (bc < end)
- {
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- tmpnumpages = *( (short *)tmpstor);
- bc+=sizeof(short);
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- tmpndxptr = key_list[ *( (short *)tmpstor) ];
- bc+=sizeof(short);
- /* check to see if a group with this name already exists */
- if (tmpndxptr->group != NULL)
- {
- newgrpptr = tmpndxptr->group;
- pbc = read_pages(pbc, tmpnumpages, newgrpptr);
- newgrpptr->numpages = newgrpptr->numpages + tmpnumpages;
- fix_icon_pointers(newgrpptr);
- bc+=sizeof(short); /* art type */
- /* skip over color if file version is >= .04 */
- if (!old_02 && !old_03)
- {
- bc+=sizeof(float);
- bc+=sizeof(float);
- bc+=sizeof(float);
- }
- /* helpfile */
- /* what to do if the new help file is different from the old one? */
- if (!(old_02 || old_03 || old_04) )
- {
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- if (indx >= 0)
- {
- if (newgrpptr->helpfile == NULL)
- {
- newgrpptr->helpfile = file_list[indx];
- file_list[indx]->occurences++;
- }
- /*
- else if (newgrpptr->helpfile != file_list[indx])
- {
- ERROR might want to notify user, or give them a chance to choose -
- ERROR which helpfile the group will use
- }
- */
- }
- bc += sizeof(short);
- }
- /* keywords */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- tmpnumkey = *( (short *) tmpstor);
- bc+=sizeof(short);
- if (tmpnumkey > 0)
- {
- if (newgrpptr->keywords == NULL)
- {
- /* do keywords the normal way */
- newgrpptr->numkey = tmpnumkey;
- count = 0;
- while (count < newgrpptr->numkey)
- {
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- bc+=sizeof(short);
- if (key_list[indx] != NULL)
- {
- if (newgrpptr->keywords == NULL)
- {
- wrdptr=(struct wordlist *)malloc(sizeof(struct wordlist));
- newgrpptr->keywords = wrdptr;
- }
- else
- {
- wrdptr->next = (struct wordlist *)malloc(sizeof(struct wordlist));
- wrdptr = wrdptr->next;
- }
- wrdptr->next = NULL;
- wrdptr->indexptr = key_list[indx];
- wrdptr->indexptr->count++;
- index_add_group(wrdptr->indexptr, newgrpptr);
- }
- count++;
- }
- }
- else
- {
- /* check each keyword to see if this group already uses it */
- count = 0;
- while (count < tmpnumkey)
- {
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- bc+=sizeof(short);
- if (key_list[indx] != NULL)
- {
- wrdptr = newgrpptr->keywords;
- while (wrdptr != NULL && wrdptr->indexptr != key_list[indx])
- {
- prevptr = wrdptr;
- wrdptr = wrdptr->next;
- }
- /* if wrdptr == key_list[indx] don't do anything else */
- if (wrdptr == NULL)
- {
- /* this keyword is not already used by this group */
- prevptr->next = (struct wordlist *)malloc(sizeof(struct wordlist));
- wrdptr = prevptr->next;
- wrdptr->next = NULL;
- wrdptr->indexptr = key_list[indx];
- wrdptr->indexptr->count++;
- index_add_group(wrdptr->indexptr, newgrpptr);
- }
- }
- count++;
- }
- }
- }
- }
- else
- {
- numnewgroups++;
- newgrpptr = new_grp();
- newgrpptr->ok = TRUE;
- if (firstgroup == NULL)
- {
- firstgroup = newgrpptr;
- }
- else
- {
- prevg -> nextgrp = newgrpptr;
- newgrpptr->prevgrp = prevg;
- }
- prevg = newgrpptr;
- lastgroup = newgrpptr;
- newgrpptr->numpages = tmpnumpages;
- pbc = read_pages(pbc, newgrpptr->numpages, newgrpptr);
- fix_icon_pointers(newgrpptr);
- newgrpptr->nameptr = tmpndxptr;
- if (newgrpptr->nameptr == NULL)
- newgrpptr->nameptr = add_keyword("dontknow");
- else
- newgrpptr->nameptr->count++;
- newgrpptr->nameptr->group = newgrpptr;
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- newgrpptr->arttype = *( (short *)tmpstor);
- bc+=sizeof(short);
- /* read the color if the version is >= .04 */
- if (!old_02 && !old_03)
- {
- for (i = 0; i < sizeof(float); i++)
- tmpstor[i] = bc[i];
- newgrpptr->covercolor[0] = *( (float *) tmpstor);
- bc+=sizeof(float);
- for (i = 0; i < sizeof(float); i++)
- tmpstor[i] = bc[i];
- newgrpptr->covercolor[1] = *( (float *) tmpstor);
- bc+=sizeof(float);
- for (i = 0; i < sizeof(float); i++)
- tmpstor[i] = bc[i];
- newgrpptr->covercolor[2] = *( (float *) tmpstor);
- bc+=sizeof(float);
- }
- else
- {
- newgrpptr->covercolor[0] = 1.0;
- newgrpptr->covercolor[1] = 0.0;
- newgrpptr->covercolor[2] = 0.0;
- }
- /* help file */
- if (!(old_02 || old_03 || old_04) )
- {
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- if (indx >= 0)
- {
- newgrpptr->helpfile = file_list[indx];
- file_list[indx]->occurences++;
- }
- bc += sizeof(short);
- }
- /* read all of the keywords */
- /* the old dumb way of doing keywords
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- newgrpptr->numkey = *( (short *) tmpstor);
- bc+=sizeof(short);
- if (newgrpptr->numkey > 0)
- {
- wrdptr=(struct wordlist *)malloc(sizeof(struct wordlist));
- newgrpptr->keywords = wrdptr;
- wrdptr->next = NULL;
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- wrdptr->indexptr = key_list[*((short*)tmpstor)];
- if (wrdptr->indexptr != NULL)
- {
- wrdptr->indexptr->count++;
- index_add_group(wrdptr->indexptr, newgrpptr);
- }
- bc+=sizeof(short);
- count = 1;
- while (count < newgrpptr->numkey)
- {
- if (wrdptr->indexptr != NULL)
- {
- wrdptr->next=(struct wordlist *)malloc(sizeof(struct wordlist));
- wrdptr = wrdptr->next;
- wrdptr->next = NULL;
- }
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- wrdptr->indexptr = find_keyword_int(*((short*)tmpstor));
- if (wrdptr->indexptr != NULL)
- {
- wrdptr->indexptr->count++;
- index_add_group(wrdptr->indexptr, newgrpptr);
- }
- bc+=sizeof(short);
- count++;
- }
- }
- */
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- newgrpptr->numkey = *( (short *) tmpstor);
- bc+=sizeof(short);
- if (newgrpptr->numkey > 0)
- {
- count = 0;
- while (count < newgrpptr->numkey)
- {
- for (i = 0; i < sizeof(short); i++)
- tmpstor[i] = bc[i];
- indx = *((short*)tmpstor);
- bc+=sizeof(short);
- if (key_list[indx] != NULL)
- {
- if (newgrpptr->keywords == NULL)
- {
- wrdptr=(struct wordlist *)malloc(sizeof(struct wordlist));
- newgrpptr->keywords = wrdptr;
- }
- else
- {
- wrdptr->next = (struct wordlist *)malloc(sizeof(struct wordlist));
- wrdptr = wrdptr->next;
- }
- wrdptr->next = NULL;
- wrdptr->indexptr = key_list[indx];
- wrdptr->indexptr->count++;
- index_add_group(wrdptr->indexptr, newgrpptr);
- }
- count++;
- }
- }
- }
- }
- /*
- lastgroup = newgrpptr;
- lastgroup->nextgrp = NULL;
- */
- numberofgroups = numberofgroups + numnewgroups;
- numberofbooks = numberofgroups;
- initbookpos();
- }
-
- #define ST 0
- #define IF 1
- #define KW 2
- #define I 3
- #define P 4
- #define G 5
- /************************************************************
- *
- * Write out the file.
- * The file begins with a 'v' and the version number.
- * Then there are six integers that represent the
- * length, in bytes, of each section of the file.
- * The first section contains the startstrings (command
- * lines for all of the demos). Each string is written to
- * the file followed by a null character.
- * Next are the icon filenames. THey are also written
- * out as strings with a null character between them. The
- * filenames and the start strings are one per demo, so they
- * are associated with the correct demo by their position in the list.
- * Then all of the keywords are written out separated
- * by a null character.
- * Then each icon in the book is written out.
- * Then each page is written out.
- * Then each groups is written out.
- *
- ************************************************************/
- write_file(char *outfilename)
- {
- struct grptmpltstruct *tmpgrp;
- struct indexlist *tmpndx;
- struct pagestruct *tmppg;
- struct filestruct *fileptr;
- int i;
- short count;
- int length;
- short bclength = 6;
- int bytecount[6];
- struct icntmpltstruct *curicon;
- char v = 'v';
- /* bytecount :
- 0 startstrings
- 1 keywords
- 2 icons
- 3 pages
- 4 groups */
- if (ASCII)
- {
- /*
- printf(" writing ascii file \n");
- */
- write_ascii(outfilename);
- }
- else
- {
- for ( i = 0; i < bclength; i++)
- bytecount[i] = 0;
- bytecount[ST] = sizeof(char) + sizeof(float) + sizeof(int) * bclength;
- if ( (outfp = fopen(outfilename,"w")) == NULL)
- {
- sprintf(msgstring, "Could not open file \n%s\nfor output ...\nFile will not be written.",outfilename);
- DialogType = 1;
- popup_Message();
- }
- else
- {
- /* write file format version number */
- fwrite(&v,sizeof(char), 1,outfp);
- fwrite(&version,sizeof(float), 1,outfp);
-
- /* leave room for the offsets into the file (bytecount) */
- fwrite(bytecount,sizeof(int), bclength,outfp);
-
- /* write all of the startstrings */
- length = strlen(firsticon->startstring);
- fwrite(firsticon->startstring,sizeof(char), length,outfp);
- bytecount[IF] = length;
- firsticon->iconnum = 0;
- curicon = firsticon->nexticntmplt;
- for (i = 1; i < numberoficons; i++)
- {
- fwrite(&nullchar,sizeof(char),1,outfp);
- bytecount[IF]++;
- length = strlen(curicon->startstring);
- fwrite(curicon->startstring,sizeof(char),length,outfp);
- bytecount[IF] = bytecount[IF] + length;
- /* renumber icons while i'm at it */
- curicon->iconnum = i;
- curicon = curicon->nexticntmplt;
- }
- fwrite(&nullchar,sizeof(char),1,outfp);
- bytecount[IF]++;
- /* write all of the filenames 8/21/91 this now includes the
- icon filenames as well as the file names for executables,
- data files, and other files that are needed to run a demo.
- If a tape is made, all of the files that the book knows
- about will be written out to tape.
- 2/18/93 This now includes the help file for showcase and
- the directory for the source code. */
- fileptr = headfile;
- bytecount[KW] = 0;
- i = 0;
- while (fileptr != NULL)
- {
- length = strlen(fileptr->name);
- if (length > 0)
- {
- fwrite(fileptr->name, sizeof(char), length, outfp);
- fwrite(&nullchar,sizeof(char),1,outfp);
- bytecount[KW] = bytecount[KW] + length + 1;
- fileptr->count = i;
- i++;
- }
- fileptr = fileptr->next;
- }
- fwrite(&i, sizeof(int),1,outfp); /* write out the number of files */
- bytecount[KW] +=sizeof(int);
- /* write out all of the keywords */
- count = 0;
- length = strlen(Index->string);
- fwrite(Index->string,sizeof(char),length,outfp);
- bytecount[I] = length;
- Index->num = count;
- tmpndx = Index->next;
- while (tmpndx != NULL)
- {
- fwrite(&nullchar,sizeof(char),1,outfp);
- bytecount[I]++;
- length = strlen(tmpndx->string);
- fwrite(tmpndx->string,sizeof(char),length,outfp);
- bytecount[I] = bytecount[I] + length;
- tmpndx->num = ++count;
- tmpndx = tmpndx->next;
- }
- fwrite(&nullchar,sizeof(char),1,outfp);
- bytecount[I]++;
- /* for each icon, call write_icon */
- bytecount[P] = 0;
- curicon = firsticon;
- while (curicon != NULL)
- {
- bytecount[P] = bytecount[P] + write_icon(curicon);
- curicon = curicon->nexticntmplt;
- }
- /* write out all of the pages */
- bytecount[G] = 0;
- tmpgrp = firstgroup;
- tmppg = tmpgrp->firstpage;
- while (tmpgrp != NULL)
- {
- bytecount[G] = bytecount[G] + write_page(tmppg);
- tmppg = tmppg->nextpage;
- if (tmppg == NULL)
- {
- tmpgrp = tmpgrp->nextgrp;
- if (tmpgrp != NULL) tmppg = tmpgrp->firstpage;
- }
- }
- /* for each group, call write_group */
- tmpgrp = firstgroup;
- while (tmpgrp != NULL)
- {
- write_group(tmpgrp);
- tmpgrp = tmpgrp->nextgrp;
- }
- /* go back to the begining and write out the bytecount again */
- rewind(outfp);
- fseek(outfp, (sizeof(char) + sizeof(float)), SEEK_SET);
- fwrite(bytecount,sizeof(int), bclength,outfp);
- fclose(outfp);
- sprintf(msgstring, "\nSaved the book file\n%s\n", FileName);
- popup_Message();
- }
- } /* end of else for if ASCII */
- }
-
- /************************************************************
- *
- * Put all of the demos in alphabetical order by name.
- *
- ************************************************************/
- alphabetize()
- {
- struct icntmpltstruct *curicon, *previcon, *beforethis, *thisicon, *nextone;
- Boolean changed, done;
- struct grptmpltstruct *grpptr;
- struct indexlist *tmpname;
-
- changed = TRUE;
- while (changed)
- {
- changed = FALSE;
- thisicon = firsticon;
- beforethis = NULL;
- while (thisicon != NULL)
- {
- nextone = thisicon->nexticntmplt;
- curicon = thisicon->nexticntmplt;
- previcon = thisicon;
- while (curicon != NULL && strcasecmp(thisicon->nameptr->string,curicon->nameptr->string)<=0)
- {
- previcon = curicon;
- curicon = curicon->nexticntmplt;
- }
- if (curicon != NULL)
- {
- changed = TRUE;
- if (thisicon == firsticon)
- firsticon = curicon;
- else
- beforethis->nexticntmplt = curicon;
- if (previcon != NULL)
- previcon->nexticntmplt = curicon->nexticntmplt;
- curicon->nexticntmplt = thisicon;
- nextone = thisicon;
- thisicon = curicon;
- }
- else
- {
- beforethis = thisicon;
- thisicon = thisicon->nexticntmplt;
- }
- }
- }
- tmpname = find_keyword("Master Index");
- grpptr = tmpname->group;
- if (grpptr != NULL)
- group_setup(firsticon,0, grpptr);
- }
-
- /************************************************************
- *
- * Read a book file. First the entire file is read into a
- * buffer. Then the buffer is read.
- * The file begins with a 'v' and the version number.
- * Then there are six integers that represent the
- * length, in bytes, of each section of the file.
- * The first section contains the startstrings (command
- * lines for all of the demos). Each string is written to
- * the file followed by a null character.
- * Next are the icon filenames. They are also written
- * out as strings with a null character between them. The
- * filenames are two per demo and the start strings are one
- * per demo, so they are associated with the correct demo by
- * their position in the list.
- * Then all of the keywords are written out separated
- * by a null character.
- * Then each icon in the book is written out.
- * Then each page is written out.
- * Then each groups is written out.
- *
- ************************************************************/
- read_file(char *filename)
- {
- int numicons, numgroups;
- int i,j,filendx;
- int *bytecount; /* 6 entries to count bytes in thefile */
- long totalbytes;
- int numread;
- char *start, *key;
- int count, length;
- char *pbeg, *beg, *end;
- char v;
- Boolean FILEERR;
- struct indexlist *ndxptr;
- float time1, time2;
- struct filestruct *fptr, *prevfptr;
- Boolean done;
- struct grptmpltstruct *grpptr;
- int acc_ret;
- char *fname;
- float tt1, tt2;
- int kl_bc, kl_size, kl_limit, kl_count;
- char *tmpstor;
- int filecount;
-
- append = FALSE;
- clock_sec(&time1);
- if (firsticon != NULL)
- {
- append = TRUE;
- setChange(TRUE);
- write_ascii("/usr/tmp/demobook_tmp.ascii");
- }
- if ( (infp = fopen(filename,"r")) == NULL)
- {
- sprintf(msgstring, "Could not open file\n%s\nfor input ... \n",filename);
- DialogType = 1;
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- }
- else
- {
- fseek(infp, 0L, SEEK_END);
- totalbytes = ftell(infp);
- rewind(infp);
- if (totalbytes > 0) {
- thefile = (char *)malloc(totalbytes+1);
- thefile[totalbytes] = '\0';
- }
- else
- {
- thefile = NULL;
- sprintf(msgstring, "\nError: file length.\nFile %s",filename);
- DialogType = 1;
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- }
- if (thefile != NULL)
- {
- /* Do not display the working dialog message, for now */
- /*
- sprintf(msgstring, "\nReading in Book File ...\n");
- UxPopupInterface(create_Working(), no_grab);
- handleMotifInterfaceEvents();
- */
- FILEERR = TRUE;
- numread = fread(thefile, sizeof(char), totalbytes, infp);
- v = thefile[0];
- tmpstor = (char *)malloc(sizeof(float) );
- for (i = 0; i < sizeof(float); i++)
- tmpstor[i] = thefile[i+1];
- version_read = (float *)malloc(sizeof(float) );
- *version_read = *(float *)(&(tmpstor[0]));
- if (v != 'v')
- {
- if (!(ASCII = read_ascii(thefile, totalbytes)))
- {
- sprintf(msgstring, "\nError: File is not recognized.\nFile <%s>", filename);
- DialogType = 1;
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- }
- }
- else /* v == 'v' this prob is a demobook binary file*/
- {
- FILEERR = FALSE;
- if (*version_read > version)
- {
- sprintf(msgstring, "Datafile %s\nis newer than the executable.",filename);
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- FILEERR = TRUE;
- }
- else
- {
- old_02 = FALSE;
- old_03 = FALSE;
- old_04 = FALSE;
- if (*version_read != version)
- {
- if (*version_read < 0.025) /* == .02 */
- old_02 = TRUE;
- else if (*version_read < 0.035) /* == .03 */
- old_03 = TRUE;
- else
- old_04 = TRUE;
- sprintf(msgstring, "File %s\nis in the old format.\nSave the file so that it will \nthen be in the new format.", filename);
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- }
- }
- /* old way */
- /*
- bytecount = (int *)(void *)&(thefile[sizeof(char)+sizeof(float)]);
- printf("old bytecount test %d %d %d %d %d \n", bytecount[0], bytecount[1], bytecount[2], bytecount[3], bytecount[4]);
- */
- /* new way under 5.0 */
- tmpstor = (char *)realloc((void *)tmpstor, (G+1)*sizeof(int) );
- for (i = 0; i < (G+1)*sizeof(int); i++)
- tmpstor[i] = thefile[i+sizeof(char)+sizeof(float)];
- bytecount = (int *) malloc ((G+1)*sizeof(int) );
- /* test bytecount */
- for (i = 0 ; i <= G; i ++)
- {
- bytecount[i] = *(int *)(void *)&(tmpstor[i*sizeof(int)]);
- if (bytecount[i] > totalbytes)
- FILEERR = TRUE;
- }
- /*
- printf("new bytecount test %d %d %d %d %d %d \n", bytecount[0], bytecount[1], bytecount[2], bytecount[3], bytecount[4], bytecount[5]);
- */
- } /* end of else for v != 'v' */
- if (!FILEERR)
- {
- /* startstrings */
- start = thefile+bytecount[ST];
- /* read the filenames */
- filendx = bytecount[ST] + bytecount[IF] + bytecount[KW];
- filendx = filendx - sizeof(int);
- for (i = 0; i < sizeof(int); i++)
- tmpstor[i] = thefile[i+filendx];
- filecount = *(int *)(&tmpstor[0]); /* this is the number of files in the book */
- filendx = bytecount[ST] + bytecount[IF];
- file_list = (struct filestruct **)malloc(filecount * sizeof(struct filestruct *) );
- kl_count = 0;
- for (j = 0; j < filecount; j++)
- {
- fptr = add_file(&(thefile[filendx]));
- fptr->occurences--;
- file_list[kl_count] = fptr;
- kl_count++;
- length = strlen(&(thefile[filendx]));
- filendx = filendx+length+1; /* string & nullchar */
- }
- if (headfile == NULL)
- {
- sprintf(msgstring, " error allocating space for files \n exiting program \n");
- DialogType = 1;
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- exit(1);
- }
- /* read all of the keywords */
- kl_size = 50;
- key_list = (struct indexlist **)malloc(kl_size * sizeof(struct indexlist *) );
- kl_limit = kl_size;
- kl_count = 0;
- kl_bc = 1;
- key = thefile+bytecount[ST] + bytecount[IF] + bytecount[KW];
- /* count is actually a running total of the bytes used by each word */
- count = 0;
- while (count < bytecount[I])
- {
- length = strlen(key);
- ndxptr = add_keyword(key);
- /* add_keyword bumps the count up one. We don't want to
- do this until we actually use the keyword */
- ndxptr->count--;
- key_list[kl_count] = ndxptr;
- kl_count++;
- if (kl_count == kl_limit)
- {
- kl_bc++;
- kl_limit = kl_size*kl_bc;
- key_list = (struct indexlist **)realloc((void *)key_list,
- kl_limit * sizeof (struct indexlist *) );
- }
- count = count + length+1;
- key = key +length+1;
- }
- for (i = kl_count; i < kl_limit; i++)
- key_list[i] = NULL;
- lastkey = kl_limit;
- /* icons are in the file next */
- count = bytecount[ST]+bytecount[IF]+bytecount[KW]+bytecount[I];
- read_icons(count,bytecount[P]);
- read_start_strings(bytecount[ST], bytecount[IF]);
- /* read groups */
- beg = thefile + bytecount[ST]+bytecount[IF]+bytecount[KW]+bytecount[I]+bytecount[P]+bytecount[G];
- pbeg = thefile + bytecount[ST]+bytecount[IF]+bytecount[KW]+bytecount[I]+bytecount[P];
- end = thefile + totalbytes;
- read_groups(beg, end, pbeg);
- /*
- curgroup = firstgroup;
- */
- grpptr = firstgroup;
- done = FALSE;
- ask_user_duplicate_icons(dup_icn_cnt);
- setup_all_groups();
- check_index();
- }
- else /* FILEERR */
- {
- if (!ASCII)
- {
- if (v == 'v' && *version_read != version)
- {
- sprintf(msgstring, "\nError: File has the wrong version number.\nFile <%s>", filename);
- DialogType = 1;
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- }
- else
- {
- sprintf(msgstring, "\nError: File is not recognized.\nFile <%s>", filename);
- DialogType = 1;
- /*
- popup_Message();
- */
- message_waiting = TRUE;
- }
- }
- }
- /* The working dialog message is not displayed, for now */
- /*
- UxPopdownInterface(Working);
- handleMotifInterfaceEvents();
- curgroup = NULL;
- */
- }
- free(thefile);
- free(version_read);
- free(tmpstor);
- if (!ASCII)
- free(bytecount);
- fclose(infp);
- }
- clock_sec(&time2);
- if (append)
- alphabetize();
- check_files();
- #ifdef HideMenu
- if (!append)
- fix_file_buttons();
- #endif
- }
-
- void tar_files()
- {
-
- struct filestruct *tmpptr;
- char *mystring;
- int total_size, st_length;
- int cur_length, block_size;
-
- block_size = 1024;
- mystring = (char *)malloc(block_size * sizeof(char));
- cur_length = block_size;
-
- tmpptr = headfile;
-
- total_size = 0;
- strcpy(mystring,"tar c /usr/demos/bin/demobook /usr/demos/data/demobook ");
- strcat(mystring,FileName);
- strcat(mystring," ");
- strcat(mystring,"/usr/demos/.login /usr/demos/.cshrc /usr/demos/.xsession ");
- strcat(mystring,"/usr/demos/.X* /usr/demos/.chestrc /usr/demos/.workspace ");
- strcat(mystring,"/usr/demos/button* /usr/demos/Application ");
- strcat(mystring,"/usr/demos/Performance /usr/demos/Tools ");
- strcat(mystring,"/usr/demos/.m* ");
- total_size = strlen(mystring);
-
- while (tmpptr != NULL)
- {
- st_length = strlen(tmpptr->name);
- total_size = total_size + st_length + 1;
- strcat(mystring,tmpptr->name);
- strcat(mystring," ");
- tmpptr = tmpptr->next;
- if (total_size >= cur_length)
- {
- cur_length = cur_length + block_size;
- mystring = (char *) realloc( (void *) mystring, cur_length);
- }
- }
- strcat(mystring," &");
- system(mystring);
- free(mystring);
- }
-
- Boolean match_color(colorA, colorB)
- float colorA[3], colorB[3];
- {
- /*
- printf("colorA = %.2f %.2f %.2f colorB = %.2f %.2f %.2f\n",
- colorA[0], colorA[1], colorA[2], colorB[0], colorB[1], colorB[2]);
- */
-
- if ((colorA[0] == colorB[0]) &&
- (colorA[1] == colorB[1]) &&
- (colorA[2] == colorB[2]))
- return(TRUE);
- else
- return(FALSE);
- }
-